<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<input type="hidden" name="selectedid" id="selectedid"/>
<input type="hidden" name="selectedname" id="selectedname"/>
<input type="hidden" id="departParam" value="<s:property value="departParam"/>"/>
<div class="modal-body">
    <div class="row">
        <div class="col-md-12" id="ajax_user_list_row">
            <legend>
                <span class="label  label-warning"> [选择部门]</span>
            </legend>

            <table id="ajax_depart_list_table">
            </table>
            <div id="ajax_depart_list_page">
            </div>
        </div>
    </div>
</div>
<div class="modal-footer">
	<a href="#ajax!flow.action" class="btn btn-primary" id="dialog-ok">确定</a>
	<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
</div>
<script>
    $("#dialog-ok").unbind("click").bind("click",function(){
        var param=$("#departParam").val();
        switch(param){
                    case 'createdepart':
                        $("#create_selectIds").val($("#selectedid").val());
                        $("#createdepart").val($("#selectedname").val());
                        break;
                    case 'readdepart':
                        $("#read_selectIds").val($("#selectedid").val());
                        $("#readdepart").val($("#selectedname").val());
                        break;
                    case 'editdepart':
                        $("#edit_selectIds").val($("#selectedid").val());
                        $("#editdepart").val($("#selectedname").val());
                        break;
                    case 'docReadDepart':
                        $("#docRead_selectIds").val($("#selectedid").val());
                        $("#docReadDepart").val($("#selectedname").val());
                        break;
                }

        gDialog.fClose();

    });
</script>
<script type="text/javascript">
function run_depart_jqgrid_function(){
    jQuery("#ajax_depart_list_table").jqGrid({
        url:'ajax-config!departGrid.action',
        mtype:"POST",
        datatype: 'json',
        page : 1,
        colNames:['id ', '名称','描述'],
        colModel : [
            {name:'id',index:'id', width:100,sortable:false,fixed:true,hidden:true},
            {name:'name',index:'name', width:150,sortable:false,search:true,sorttype:'string'},
            {name:'description',index:'description',width:250,sortable:false},
        ],
        rowNum : 10,
        rowList:[10,20,30],
        pager : '#ajax_depart_list_page',
        sortname : 'id',
        sortorder : "asc",
        gridComplete:function(){
            var param=$("#departParam").val();
            jqGridStyle();
                switch(param){
                    case 'createdepart':
                        $("#ajax_depart_list_table").multiSelect("initValue",{"gridId":"ajax_depart_list_table","inputId":"create_selectIds","inputName":"createdepart"});
                        break;
                    case 'readdepart':
                       $("#ajax_depart_list_table").multiSelect("initValue",{"gridId":"ajax_depart_list_table","inputId":"read_selectIds","inputName":"readdepart"});
                        break;
                    case 'editdepart':
                        $("#ajax_depart_list_table").multiSelect("initValue",{"gridId":"ajax_depart_list_table","inputId":"edit_selectIds","inputName":"editdepart"});
                        break;
                    case 'docReadDepart':
                        $("#ajax_depart_list_table").multiSelect("initValue",{"gridId":"ajax_depart_list_table","inputId":"docRead_selectIds","inputName":"docReadDepart"});
                        break;
                }
            $(".ui-jqgrid-bdiv").css("overflow-x","hidden");
        },
        onSelectRow: function (rowId, status, e) {
            if(status){
                $("#ajax_depart_list_table").multiSelect("addValue",{"gridId":"ajax_depart_list_table","rowId":rowId});
            } else {
                $("#ajax_depart_list_table").multiSelect("delValue",{"gridId":"ajax_depart_list_table","rowId":rowId});
            }
        },
	    jsonReader: {
		    root: "dataRows",
			page: "page",
			total: "total",
			records: "records",
			repeatitems : false
		},

		multiselect: true,
        rownumbers:true,
        gridview:true,
        shrinkToFit:true,
        forceFit:true,
        viewrecords: true,
        autowidth: true,
        height : 'auto',
        loadComplete: function() {
        }
    });
    $(window).on('resize.jqGrid', function() {
		jQuery("#ajax_depart_list_table").jqGrid('setGridWidth', $("#ajax_depart_list_row").width()-10);
	})

    jQuery("#ajax_depart_list_table").jqGrid('navGrid', "#ajax_depart_list_page", {
		edit : false,
		add : false,
		del : false,
		search:false
	});

	jQuery("#ajax_depart_list_table").jqGrid('filterToolbar',{searchOperators : false,stringResult:true});
}

</script>
<script type="text/javascript">
    $(function(){
        run_depart_jqgrid_function();
    });
</script>